package com.zjw.factory;


import com.zjw.strategy.ProductStrategy;
import com.zjw.strategy.productStrategyImpl.Discount4Product;
import com.zjw.strategy.productStrategyImpl.NoDiscount4Product;
import com.zjw.strategySign.Sign;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 商品价格计算的策略类工厂
 */
@Component
public class ProductStrategyFactory {


    @Resource
    private Discount4Product discount4Product;

    @Resource
    private NoDiscount4Product noDiscount4Product;

    private static Map<String, ProductStrategy> productStrategyMap = new HashMap<>();

    @PostConstruct
    public void init() {
        productStrategyMap.put(Sign.PRODUCT_DISCOUNT, discount4Product);
        productStrategyMap.put(Sign.PRODUCT_DISCOUNT_NO, noDiscount4Product);
    }

    public ProductStrategy getProductStrategy(String strategyType) {
        return productStrategyMap.get(strategyType);
    }
}
